const http = require('http');
const fs = require('fs');
const {httpReadFile,httpReadFileWithData} = require('./utils/file-util')
const server = http.createServer();
const url = require('url')

server.listen(3308, function () {
    console.log("留言板服务启动成功~");
})


const list = [
    {name: 'gjq',content:'燥起来'},
]


server.on('request', function (request, response) {
    console.log(request.url);
    console.log();
    if (request.url === '/') {

        // httpReadFile('./views/index.html', response)
        httpReadFileWithData('./views/index.html', response,{list})
    }
    // 处理 这个路径的时候进行处理
    else if (request.url.startsWith('/node_modules')) {
        httpReadFile("."+request.url,response)
    }
    else if (request.url === '/add') {
        httpReadFile('./views/add.html',response)
        }
    else {
        httpReadFile('./views/error.html',response)
    }
})


